package com.ruoyi.web.controller.salon;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SalonCategory;
import com.ruoyi.system.service.ISalonCategoryService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * categoryController
 *
 * @author 23
 * @date 2022-03-30
 */
@RestController
@RequestMapping("/system/category")
public class SalonCategoryController extends BaseController
{
    @Autowired
    private ISalonCategoryService salonCategoryService;

    /**
     * 查询category列表
     */
    @PreAuthorize("@ss.hasPermi('system:category:list')")
    @GetMapping("/list")
    public TableDataInfo list(SalonCategory salonCategory)
    {
        startPage();
        List<SalonCategory> list = salonCategoryService.selectSalonCategoryList(salonCategory);
        return getDataTable(list);
    }

    /**
     * 导出category列表
     */
    @PreAuthorize("@ss.hasPermi('system:category:export')")
    @Log(title = "category", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SalonCategory salonCategory)
    {
        List<SalonCategory> list = salonCategoryService.selectSalonCategoryList(salonCategory);
        ExcelUtil<SalonCategory> util = new ExcelUtil<SalonCategory>(SalonCategory.class);
        util.exportExcel(response, list, "category数据");
    }

    /**
     * 获取category详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:category:query')")
    @GetMapping(value = "/{categoryId}")
    public AjaxResult getInfo(@PathVariable("categoryId") Integer categoryId)
    {
        return AjaxResult.success(salonCategoryService.selectSalonCategoryByCategoryId(categoryId));
    }

    /**
     * 新增category
     */
    @PreAuthorize("@ss.hasPermi('system:category:add')")
    @Log(title = "category", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SalonCategory salonCategory)
    {
        return toAjax(salonCategoryService.insertSalonCategory(salonCategory));
    }

    /**
     * 修改category
     */
    @PreAuthorize("@ss.hasPermi('system:category:edit')")
    @Log(title = "category", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SalonCategory salonCategory)
    {
        return toAjax(salonCategoryService.updateSalonCategory(salonCategory));
    }

    /**
     * 删除category
     */
    @PreAuthorize("@ss.hasPermi('system:category:remove')")
    @Log(title = "category", businessType = BusinessType.DELETE)
	@DeleteMapping("/{categoryIds}")
    public AjaxResult remove(@PathVariable Integer[] categoryIds)
    {
        return toAjax(salonCategoryService.deleteSalonCategoryByCategoryIds(categoryIds));
    }
}
